<link href="${rc.getContextPath()}/manage/css/dwzCustomCss/dwz.custom.css?v=${ver}" rel="stylesheet" type="text/css">
<style>
.tree .workUnit a {
	color: #4C9ED9;
}
.tree .andonGroup a {
	color: #39AA46;
}
</style>
<div class="pageContent">
	<div class="treeleft" style="width: 260px; float: left; border-right: 1px solid #D8DFE5;">
		<div class="mini-toolbar">
			<input type="text" id="workcenterSearch" /> <a class="buttonActive" href="javascript:void(0)" id="searchTree"> <span><@label
					key='search.B'>搜索</@label></span>
			</a>
		</div>
		
		<div id="menuBar" class="pBar pBarBorder">
			<ul class="toolBar">
				<li>
					<a class="collapse" id="collapsable" title='<@label key="collapseAll.D">全部收起</@label>'> 
						<span><@label key="collapse.B">收起</@label></span>
					</a>
				</li>
				<li>
					<a class="expand" id="expandable" title='<@label key="expandAll.D">全部展开</@label>'> 
						<span><@label key="expand.B">展开</@label></span>
					</a>
				</li>
			</ul>
		</div>
		<div id="workcenterTree" layoutH="68">
			<#if workCentersTree??>
			<ul class="tree treeFolder expand">
				<@macroWorkCenterTree children=workCentersTree />
			</ul>
			</#if>
		</div>
		<!-- 递归产生树的宏定义 -->
		<#macro macroWorkCenterTree children> 
			<#if children?? && children?size gt 0> 
				<#list children as workCenter>
					<li class='workCenter' workcenterCode="${workCenter.workCenterCode!''}">
						<a onclick="$(this).trigger('check');" title="工作中心">${workCenter.workCenterText!''}</a>
						<#if workCenter.childrens?? || workCenter.workUnits?size gt 0>
							<ul>
								<@macroWorkCenterTree children = workCenter.childrens /> 
								<#list workCenter.workUnits as workUnit>
									<li class="workUnit" workunitCode="${workUnit.workUnitCode!''}">
										<a onclick="$(this).trigger('check');" title="作业单元">${workUnit.workUnitText!''}</a>
										<#if workUnit.andongroups && workUnit.andongroups?size gt 0>
											<ul>
												<#list workUnit.andongroups as andonGroup>
												<li class="andonGroup" workunitCode="${workUnit.workUnitCode!''}" andonGroup="${andonGroup.andonGroup!''}">
													<a onclick="$(this).trigger('check');" title="按灯组">${andonGroup.andonGroup!''}</a>
												</li>
												</#list>
											</ul>
										</#if>
									</li> 
								</#list>
							</ul> 
						</#if>
					</li> 
				</#list> 
			</#if> 
		</#macro>
	</div>
	<div style="margin-left: 261px; margin-top: -1px;">
		<div id="jGridForAndonList" style="float: left; width: 100%;"></div>
	</div>
</div>
<script type="text/javascript">
	(function($) {
		var $page = DWZ.context(), $grid = $('#jGridForAndonList', $page), postData = {};
		$grid.jGrid({
			layoutH: 155,
			base: '${rc.getContextPath()}/manage/andon/',
			url: 'getAndonListByCondition',
			autoLoad: true,
			columns: [{
				field: '',
				group: 'ids',
				type: 'checkbox',
				tdrender : function(td,data){
					var value=[
					       'workUnitCode : "'+data["workUnitCode"]+'"',
					       'workUnitText : "'+data["workUnitText"]+'"',
					       'workCenterCode : "'+data["workCenterCode"]+'"',
					       'workCenterText : "'+data["workCenterCode"]+'"',
					       'andonCode : "'+data["andonCode"]+'"',
					       'andonType : "'+data["andonType"]+'"',
					       'andonTypeText : "'+data["typeText"]+'"'
					]
					
					td.empty().html("<input type='checkbox' name='ids' value='{"+value.join(",")+"}' />" );
				},
				width: 22
			}, {
				field: 'andonCode',
				text: 'ANDON编号',
				width: 100,
				query: true
			}, {
				field: 'andonText',
				text: 'ANDON描述',
				width: 100,
				query: true
			}, {
				field: 'typeText',
				text: 'ANDON类型',
				width: 100,
				query: true,
                queryField: 'andonTypeCode',
                queryType: 'select', 
                queryOptions: [
                    {value: '', label: '<@label key="all.C">所有</@label>'}
                    <#list andonTypes as andonType>
                    ,{value: "${andonType.andonTypeCode}", label: "${andonType.typeText}"}
                    </#list>
                ]
			}, {
				field: 'templateText',
				text: 'ANDON模板',
				width: 100
			}, {
				field: 'eventText',
				text: '事件',
				width: 100
			}, {
				field: 'ruleText',
				text: '消息通知规则',
				width: 100
			}, {
				field: 'alarmFlag',
				text: '报警',
				width: 100,
				transform: function(data) {
					if (data == 1) {
						return '<@label key="no.C">否</@label>';
					} else if (data == 0) {
						return '<@label key="yes.C">是</@label>';
					}
				}
			}, {
				field: 'lockFlag',
				text: '启用',
				width: 100,
				transform: function(data) {
					if (data == 1) {
						return '<@label key="no.C">否</@label>';
					} else if (data == 0) {
						return '<@label key="yes.C">是</@label>';
					}
				}
			}],
			getQueryData: function() {
				return postData;
			},
			gridbars: [{
				icon: 'add',
				text: '<@label key="choose.B"></@label>',
				title: '选择',
				target : 'action',
				action : function(){
					var $page = DWZ.context();
					var datas =[];
					$.each($("input[type='checkbox']:checked",$page),function(index,e){
						if($(e).attr("value") !== "on"){
							datas.push(eval("(" + $(e).attr("value") + ")"));
						}
					})
					
					$.messageRule.bringBackToAndonGrid(datas);
					 $.pdialog.closeCurrent();
				}
			}]
		});
		
		$("#searchTree", $page).baseTreeSearch({
			inputTextId: "#workcenterSearch",
			alertMsg: "<@label key='Tree_search_Input.D'>输入名称进行查询</@label>", //提示内容，要考虑国际化，传自后台
			$p: $page
		});

		$("#collapsable", $page)._treeCollapsable({
			$p: $page
		})

		$("#expandable", $page)._treeExpandable({
			$p: $page
		});
		
		var $rename = $('#rename', $page), $noright = $('#noright', $page);

		$('#workcenterTree .tree', $page).on('check', '.workCenter, .workUnit, .andonGroup', function(event) {
			var $this = $(this);
			postData = {};
			if ($this.is('.workCenter')) {
				postData.workCenterCode = $this.attr('workcenterCode');
				postData.workCenterCodes = [];
				postData.workCenterCodes.push(postData.workCenterCode);
				$this.find('.workCenter').each(function(){
					postData.workCenterCodes.push($(this).attr('workcenterCode'));
				});
				postData.workCenterCodes = postData.workCenterCodes.join(',');
			} else if ($this.is('.workUnit')) {
				postData.workUnitCode = $this.attr('workunitCode');
			} else if ($this.is('.andonGroup')) {
				postData.workUnitCode = $this.attr('workunitCode');
				postData.andonGroup = $this.attr('andonGroup');
			}
			if ($this.is('.andonGroup')) {
				$noright.hide();
				$rename.show();
			} else {
				$rename.hide();
				$noright.show();
			}
			
			$grid.jGrid('loadData');
			return false;
		});
		
        $("ul.searchContent",$page).css({
               "overflow": "visible"
           })
           
        $("ul.searchContent > li",$page).css({
        	"margin-top" : "5px",
        	"width" : "250px"
        })
		
		
		
	})(jQuery);
</script>